import Request from "./Request"
const regions={
    region1List:[],
    region2List:[],
    region3List:[],
    async init(){
        if(this.region1List.length>0){
            return;
        }
        let res = await Request.post("exclude", "GetSysDefine");
        if(res.code==0){
            this.region1List = [];
            this.region2List = [];
            this.region3List = [];
            let proObj1={};
            let proObj2={};
            if(res.data.Region1 != null && res.data.Region2 != null && res.data.Region3 != null){
                res.data.Region1.forEach(pro=>{
                    proObj1[pro.id] = {"id":pro.id,"name":pro.name,"list":[]};
                    this.region1List.push({"id":pro.id,"name":pro.name})
                });
                res.data.Region2.forEach(area=>{
                    proObj1[area.parentId].list.push({"id":area.id,"name":area.name})
                    proObj2[area.id]= {"id":area.id,"name":proObj1[area.parentId].name+"-"+area.name,"list":[]};

                });
                for(var key in proObj1){
                    this.region2List.push(proObj1[key]);
                }
                res.data.Region3.forEach(city=>{
                    proObj2[city.parentId]["list"].push({"id":city.id,"name":city.name});
                })
                for(var key in proObj2){
                    this.region3List.push(proObj2[key]);
                }
            }
        }
    },
}
export default regions;